<script setup>
import { ref, reactive } from 'vue'

// 默认插槽示例数据
const defaultSlotContent = ref('这是默认插槽的内容')
const cardTitle = ref('卡片标题')
const cardContent = ref('这是卡片的主要内容，通过默认插槽传入。')

// 具名插槽示例数据
const articleData = reactive({
  title: 'Vue 插槽详解',
  author: '张三',
  publishDate: '2024-01-15',
  content: '插槽是Vue组件系统中一个非常强大的功能，它允许我们创建可复用的组件模板。',
  tags: ['Vue', '前端', '组件']
})

// 作用域插槽示例数据
const userList = ref([
  { id: 1, name: '张三', age: 25, role: '开发者', avatar: '👨‍💻', status: 'online' },
  { id: 2, name: '李四', age: 30, role: '设计师', avatar: '👩‍🎨', status: 'offline' },
  { id: 3, name: '王五', age: 28, role: '产品经理', avatar: '👨‍💼', status: 'online' },
  { id: 4, name: '赵六', age: 32, role: '测试工程师', avatar: '👩‍🔬', status: 'busy' }
])

const productList = ref([
  { id: 1, name: 'MacBook Pro', price: 12999, category: '笔记本', rating: 4.8, stock: 10 },
  { id: 2, name: 'iPhone 15', price: 5999, category: '手机', rating: 4.9, stock: 25 },
  { id: 3, name: 'iPad Air', price: 4399, category: '平板', rating: 4.7, stock: 15 },
  { id: 4, name: 'AirPods Pro', price: 1899, category: '耳机', rating: 4.6, stock: 30 }
])

// 动态插槽示例
const currentView = ref('card')
const viewOptions = ['card', 'list', 'table']

// 条件插槽示例
const showHeader = ref(true)
const showFooter = ref(true)
const showSidebar = ref(false)

// 方法
const updateContent = () => {
  cardContent.value = `更新时间: ${new Date().toLocaleTimeString()}`
}

const switchView = (view) => {
  currentView.value = view
}

const toggleSection = (section) => {
  switch (section) {
    case 'header':
      showHeader.value = !showHeader.value
      break
    case 'footer':
      showFooter.value = !showFooter.value
      break
    case 'sidebar':
      showSidebar.value = !showSidebar.value
      break
  }
}

const getStatusColor = (status) => {
  switch (status) {
    case 'online': return '#52c41a'
    case 'offline': return '#d9d9d9'
    case 'busy': return '#faad14'
    default: return '#1890ff'
  }
}

const getRatingStars = (rating) => {
  const fullStars = Math.floor(rating)
  const hasHalfStar = rating % 1 !== 0
  let stars = '★'.repeat(fullStars)
  if (hasHalfStar) stars += '☆'
  return stars
}
</script>

<template>
  <div class="component-slots">
    <!-- 页面标题 -->
    <div class="header">
      <h1 class="title">🔌 Vue 插槽教程</h1>
      <p class="subtitle">深入理解插槽机制：默认插槽、具名插槽、作用域插槽</p>
    </div>

    <!-- 插槽概念介绍 -->
    <div class="section">
      <h2 class="section-title">📚 插槽基础概念</h2>
      <div class="concept-grid">
        <div class="concept-card">
          <div class="concept-icon">🔌</div>
          <h3>什么是插槽</h3>
          <p>插槽是组件的内容分发机制，允许父组件向子组件传递模板内容</p>
        </div>
        
        <div class="concept-card">
          <div class="concept-icon">🎯</div>
          <h3>插槽的作用</h3>
          <p>提高组件的灵活性和复用性，实现内容的动态分发</p>
        </div>
        
        <div class="concept-card">
          <div class="concept-icon">🔄</div>
          <h3>插槽类型</h3>
          <p>默认插槽、具名插槽、作用域插槽三种类型</p>
        </div>
      </div>
    </div>

    <!-- 默认插槽 -->
    <div class="section">
      <h2 class="section-title">🔌 默认插槽 (Default Slots)</h2>
      <div class="demo-container">
        <div class="code-demo">
          <h3>子组件定义</h3>
          <pre class="code-block"><code>&lt;!-- BaseCard.vue --&gt;
&lt;template&gt;
  &lt;div class="card"&gt;
    &lt;div class="card-header"&gt;
      &lt;h3&gt;{{ title }}&lt;/h3&gt;
    &lt;/div&gt;
    &lt;div class="card-body"&gt;
      &lt;!-- 默认插槽 --&gt;
      &lt;slot&gt;
        &lt;!-- 后备内容 --&gt;
        &lt;p&gt;这是默认内容&lt;/p&gt;
      &lt;/slot&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/template&gt;</code></pre>
          
          <h3>父组件使用</h3>
          <pre class="code-block"><code>&lt;template&gt;
  &lt;BaseCard title="我的卡片"&gt;
    &lt;!-- 插槽内容 --&gt;
    &lt;p&gt;这是通过插槽传入的内容&lt;/p&gt;
    &lt;button&gt;操作按钮&lt;/button&gt;
  &lt;/BaseCard&gt;
  
  &lt;!-- 不传入内容，显示后备内容 --&gt;
  &lt;BaseCard title="空卡片" /&gt;
&lt;/template&gt;</code></pre>
        </div>
        
        <div class="live-demo">
          <h3>实际效果</h3>
          <div class="demo-area">
            <!-- 模拟默认插槽组件 -->
            <div class="slot-demo">
              <div class="base-card">
                <div class="card-header">
                  <h4>{{ cardTitle }}</h4>
                </div>
                <div class="card-body">
                  <p>{{ cardContent }}</p>
                  <button class="demo-btn primary" @click="updateContent">
                    更新内容
                  </button>
                </div>
              </div>
              
              <div class="base-card">
                <div class="card-header">
                  <h4>空卡片</h4>
                </div>
                <div class="card-body">
                  <p class="fallback-content">这是后备内容（没有传入插槽内容时显示）</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <div class="info-box">
        <h4>🔍 默认插槽特点</h4>
        <ul>
          <li>最简单的插槽类型，不需要指定名称</li>
          <li>可以提供后备内容，当没有传入内容时显示</li>
          <li>父组件的内容会替换子组件的 &lt;slot&gt; 标签</li>
          <li>适合简单的内容分发场景</li>
        </ul>
      </div>
    </div>

    <!-- 具名插槽 -->
    <div class="section">
      <h2 class="section-title">🏷️ 具名插槽 (Named Slots)</h2>
      <div class="demo-container">
        <div class="code-demo">
          <h3>子组件定义</h3>
          <pre class="code-block"><code>&lt;!-- ArticleLayout.vue --&gt;
&lt;template&gt;
  &lt;article class="article"&gt;
    &lt;header class="article-header"&gt;
      &lt;slot name="header"&gt;
        &lt;h2&gt;默认标题&lt;/h2&gt;
      &lt;/slot&gt;
    &lt;/header&gt;
    
    &lt;aside class="article-sidebar"&gt;
      &lt;slot name="sidebar"&gt;
        &lt;p&gt;侧边栏内容&lt;/p&gt;
      &lt;/slot&gt;
    &lt;/aside&gt;
    
    &lt;main class="article-content"&gt;
      &lt;slot&gt;
        &lt;!-- 默认插槽 --&gt;
        &lt;p&gt;文章内容&lt;/p&gt;
      &lt;/slot&gt;
    &lt;/main&gt;
    
    &lt;footer class="article-footer"&gt;
      &lt;slot name="footer"&gt;
        &lt;p&gt;默认页脚&lt;/p&gt;
      &lt;/slot&gt;
    &lt;/footer&gt;
  &lt;/article&gt;
&lt;/template&gt;</code></pre>
          
          <h3>父组件使用</h3>
          <pre class="code-block"><code>&lt;template&gt;
  &lt;ArticleLayout&gt;
    &lt;template #header&gt;
      &lt;h1&gt;article.title&lt;/h1&gt;
      &lt;p&gt;作者: article.author&lt;/p&gt;
    &lt;/template&gt;
    
    &lt;template #sidebar&gt;
      &lt;div class="tags"&gt;
        &lt;span v-for="tag in article.tags" :key="tag"&gt;
           tag 
        &lt;/span&gt;
      &lt;/div&gt;
    &lt;/template&gt;
    
    &lt;!-- 默认插槽内容 --&gt;
    &lt;p&gt;article.content &lt;/p&gt;
    
    &lt;template #footer&gt;
      &lt;p&gt;发布时间:  article.publishDate &lt;/p&gt;
    &lt;/template&gt;
  &lt;/ArticleLayout&gt;
&lt;/template&gt;</code></pre>
        </div>
        
        <div class="live-demo">
          <h3>实际效果</h3>
          <div class="demo-area">
            <!-- 模拟具名插槽组件 -->
            <div class="article-layout">
              <header class="article-header">
                <h3>{{ articleData.title }}</h3>
                <p class="author-info">作者: {{ articleData.author }}</p>
              </header>
              
              <div class="article-main">
                <aside class="article-sidebar">
                  <div class="tags">
                    <span 
                      v-for="tag in articleData.tags" 
                      :key="tag"
                      class="tag"
                    >
                      {{ tag }}
                    </span>
                  </div>
                </aside>
                
                <main class="article-content">
                  <p>{{ articleData.content }}</p>
                </main>
              </div>
              
              <footer class="article-footer">
                <p>发布时间: {{ articleData.publishDate }}</p>
              </footer>
            </div>
          </div>
        </div>
      </div>
      
      <div class="info-box">
        <h4>🔍 具名插槽特点</h4>
        <ul>
          <li>通过 name 属性为插槽指定名称</li>
          <li>使用 &lt;template #slotName&gt; 或 &lt;template v-slot:slotName&gt; 传入内容</li>
          <li>可以同时使用多个具名插槽</li>
          <li>适合复杂布局的内容分发</li>
        </ul>
      </div>
    </div>

    <!-- 作用域插槽 -->
    <div class="section">
      <h2 class="section-title">🎯 作用域插槽 (Scoped Slots)</h2>
      <div class="demo-container">
        <div class="code-demo">
          <h3>子组件定义</h3>
          <pre class="code-block"><code>&lt;!-- UserList.vue --&gt;
&lt;template&gt;
  &lt;div class="user-list"&gt;
    &lt;div 
      v-for="user in users" 
      :key="user.id"
      class="user-item"
    &gt;
      &lt;slot 
        :user="user" 
        :index="index"
        :isOnline="user.status === 'online'"
      &gt;
        &lt;!-- 后备内容 --&gt;
        &lt;p&gt;user.name &lt;/p&gt;
      &lt;/slot&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/template&gt;</code></pre>
          
          <h3>父组件使用</h3>
          <pre class="code-block"><code>&lt;template&gt;
  &lt;UserList :users="userList"&gt;
    &lt;template #default="{ user, index, isOnline }"&gt;
      &lt;div class="custom-user-card"&gt;
        &lt;span&gt;index + 1. user.name &lt;/span&gt;
        &lt;span :class="{ online: isOnline }"&gt;
          user.role 
        &lt;/span&gt;
      &lt;/div&gt;
    &lt;/template&gt;
  &lt;/UserList&gt;
  
  &lt;!-- 不同的展示方式 --&gt;
  &lt;UserList :users="userList"&gt;
    &lt;template #default="{ user }"&gt;
      &lt;div class="simple-user"&gt;
        user.avatar user.name
      &lt;/div&gt;
    &lt;/template&gt;
  &lt;/UserList&gt;
&lt;/template&gt;</code></pre>
        </div>
        
        <div class="live-demo">
          <h3>实际效果</h3>
          <div class="demo-area">
            <!-- 用户列表作用域插槽示例 -->
            <div class="scoped-demo">
              <h4>用户列表 - 卡片视图</h4>
              <div class="user-grid">
                <div 
                  v-for="(user, index) in userList" 
                  :key="user.id"
                  class="user-card"
                >
                  <div class="user-avatar">{{ user.avatar }}</div>
                  <div class="user-info">
                    <h5>{{ index + 1 }}. {{ user.name }}</h5>
                    <p class="user-role">{{ user.role }}</p>
                    <span 
                      class="user-status"
                      :style="{ backgroundColor: getStatusColor(user.status) }"
                    >
                      {{ user.status }}
                    </span>
                  </div>
                </div>
              </div>
              
              <h4>用户列表 - 简单视图</h4>
              <div class="user-simple-list">
                <div 
                  v-for="user in userList" 
                  :key="user.id"
                  class="user-simple-item"
                >
                  {{ user.avatar }} {{ user.name }} - {{ user.role }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <div class="info-box">
        <h4>🔍 作用域插槽特点</h4>
        <ul>
          <li>子组件可以向插槽传递数据</li>
          <li>父组件可以访问子组件的数据来自定义渲染</li>
          <li>使用 v-slot="slotProps" 或解构语法接收数据</li>
          <li>实现了数据和渲染的分离</li>
        </ul>
      </div>
    </div>

    <!-- 高级插槽用法 -->
    <div class="section">
      <h2 class="section-title">🚀 高级插槽用法</h2>
      
      <!-- 动态插槽名 -->
      <div class="advanced-demo">
        <h3>动态插槽名</h3>
        <div class="demo-container">
          <div class="code-demo">
            <pre class="code-block"><code>&lt;template&gt;
  &lt;BaseLayout&gt;
    &lt;template #[dynamicSlotName]&gt;
      &lt;p&gt;动态插槽内容&lt;/p&gt;
    &lt;/template&gt;
  &lt;/BaseLayout&gt;
&lt;/template&gt;

&lt;script setup&gt;
const dynamicSlotName = ref('header')
&lt;/script&gt;</code></pre>
          </div>
          
          <div class="live-demo">
            <div class="dynamic-slots">
              <div class="view-switcher">
                <button 
                  v-for="view in viewOptions" 
                  :key="view"
                  class="demo-btn"
                  :class="{ active: currentView === view }"
                  @click="switchView(view)"
                >
                  {{ view }} 视图
                </button>
              </div>
              
              <div class="dynamic-content">
                <div v-if="currentView === 'card'" class="view-card">
                  <h5>卡片视图</h5>
                  <div class="product-cards">
                    <div 
                      v-for="product in productList.slice(0, 2)" 
                      :key="product.id"
                      class="product-card"
                    >
                      <h6>{{ product.name }}</h6>
                      <p>¥{{ product.price }}</p>
                      <p>{{ getRatingStars(product.rating) }}</p>
                    </div>
                  </div>
                </div>
                
                <div v-else-if="currentView === 'list'" class="view-list">
                  <h5>列表视图</h5>
                  <div class="product-list">
                    <div 
                      v-for="product in productList" 
                      :key="product.id"
                      class="product-list-item"
                    >
                      <span class="product-name">{{ product.name }}</span>
                      <span class="product-price">¥{{ product.price }}</span>
                      <span class="product-stock">库存: {{ product.stock }}</span>
                    </div>
                  </div>
                </div>
                
                <div v-else-if="currentView === 'table'" class="view-table">
                  <h5>表格视图</h5>
                  <table class="product-table">
                    <thead>
                      <tr>
                        <th>产品名称</th>
                        <th>价格</th>
                        <th>评分</th>
                        <th>库存</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr v-for="product in productList" :key="product.id">
                        <td>{{ product.name }}</td>
                        <td>¥{{ product.price }}</td>
                        <td>{{ product.rating }}</td>
                        <td>{{ product.stock }}</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 条件插槽 -->
      <div class="advanced-demo">
        <h3>条件插槽</h3>
        <div class="demo-container">
          <div class="code-demo">
            <pre class="code-block"><code>&lt;template&gt;
  &lt;BaseLayout&gt;
    &lt;template #header v-if="showHeader"&gt;
      &lt;h2&gt;页面标题&lt;/h2&gt;
    &lt;/template&gt;
    
    &lt;template #sidebar v-if="showSidebar"&gt;
      &lt;nav&gt;导航菜单&lt;/nav&gt;
    &lt;/template&gt;
    
    &lt;p&gt;主要内容&lt;/p&gt;
    
    &lt;template #footer v-if="showFooter"&gt;
      &lt;p&gt;页脚信息&lt;/p&gt;
    &lt;/template&gt;
  &lt;/BaseLayout&gt;
&lt;/template&gt;</code></pre>
          </div>
          
          <div class="live-demo">
            <div class="conditional-slots">
              <div class="toggle-controls">
                <label class="toggle-item">
                  <input 
                    type="checkbox" 
                    v-model="showHeader"
                  >
                  显示头部
                </label>
                <label class="toggle-item">
                  <input 
                    type="checkbox" 
                    v-model="showSidebar"
                  >
                  显示侧边栏
                </label>
                <label class="toggle-item">
                  <input 
                    type="checkbox" 
                    v-model="showFooter"
                  >
                  显示页脚
                </label>
              </div>
              
              <div class="layout-preview">
                <div class="layout-container">
                  <header v-if="showHeader" class="layout-header">
                    <h5>页面头部</h5>
                  </header>
                  
                  <div class="layout-main">
                    <aside v-if="showSidebar" class="layout-sidebar">
                      <p>侧边栏</p>
                    </aside>
                    
                    <main class="layout-content">
                      <p>主要内容区域</p>
                    </main>
                  </div>
                  
                  <footer v-if="showFooter" class="layout-footer">
                    <p>页面页脚</p>
                  </footer>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 插槽最佳实践 -->
    <div class="section">
      <h2 class="section-title">💡 插槽最佳实践</h2>
      <div class="best-practices">
        <div class="practice-card">
          <div class="practice-icon">📝</div>
          <h4>命名规范</h4>
          <ul>
            <li>使用语义化的插槽名称</li>
            <li>避免使用过于通用的名称</li>
            <li>保持命名的一致性</li>
          </ul>
        </div>
        
        <div class="practice-card">
          <div class="practice-icon">🎯</div>
          <h4>合理使用</h4>
          <ul>
            <li>简单内容用默认插槽</li>
            <li>复杂布局用具名插槽</li>
            <li>数据展示用作用域插槽</li>
          </ul>
        </div>
        
        <div class="practice-card">
          <div class="practice-icon">🔄</div>
          <h4>后备内容</h4>
          <ul>
            <li>为插槽提供合理的后备内容</li>
            <li>后备内容应该是有意义的</li>
            <li>考虑用户体验</li>
          </ul>
        </div>
        
        <div class="practice-card">
          <div class="practice-icon">⚡</div>
          <h4>性能考虑</h4>
          <ul>
            <li>避免在插槽中进行复杂计算</li>
            <li>合理使用 v-if 和 v-show</li>
            <li>注意作用域插槽的性能影响</li>
          </ul>
        </div>
      </div>
    </div>

    <!-- 练习任务 -->
    <div class="section">
      <h2 class="section-title">🎯 练习任务</h2>
      <div class="exercise-list">
        <div class="exercise-item">
          <h4>任务 1: 模态框组件</h4>
          <p>创建一个模态框组件，使用具名插槽分别定义标题、内容和操作按钮区域</p>
        </div>
        
        <div class="exercise-item">
          <h4>任务 2: 数据表格组件</h4>
          <p>创建一个表格组件，使用作用域插槽让父组件自定义每一行的渲染方式</p>
        </div>
        
        <div class="exercise-item">
          <h4>任务 3: 卡片列表组件</h4>
          <p>创建一个卡片列表组件，支持不同的展示模式（网格、列表、详情）</p>
        </div>
        
        <div class="exercise-item">
          <h4>任务 4: 布局组件</h4>
          <p>创建一个响应式布局组件，支持头部、侧边栏、内容、页脚的灵活组合</p>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.component-slots {
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: white;
}

/* 页面头部 */
.header {
  text-align: center;
  margin-bottom: 40px;
}

.title {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 10px;
  background: linear-gradient(45deg, #fff, #e0e0e0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
  margin: 0;
}

/* 章节样式 */
.section {
  margin-bottom: 40px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  padding: 25px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.section-title {
  font-size: 1.8rem;
  margin-bottom: 20px;
  color: #fff;
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 10px;
}

/* 概念网格 */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.concept-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: all 0.3s ease;
}

.concept-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.concept-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.concept-card h3 {
  margin: 0 0 10px 0;
  font-size: 1.2rem;
}

.concept-card p {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
  line-height: 1.5;
}

/* 演示容器 */
.demo-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.code-demo, .live-demo {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 20px;
}

.code-demo h3, .live-demo h3 {
  margin: 0 0 15px 0;
  font-size: 1.1rem;
}

.code-block {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 15px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  overflow-x: auto;
  margin: 0 0 15px 0;
}

.demo-area {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 15px;
}

/* 按钮样式 */
.demo-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 0 5px 5px 0;
}

.demo-btn.primary {
  background: linear-gradient(45deg, #4facfe, #00f2fe);
  color: white;
}

.demo-btn.active {
  background: linear-gradient(45deg, #56ab2f, #a8e6cf);
  color: white;
}

.demo-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* 默认插槽演示 */
.slot-demo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.base-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.card-header {
  background: rgba(255, 255, 255, 0.1);
  padding: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.card-header h4 {
  margin: 0;
  font-size: 1.1rem;
}

.card-body {
  padding: 15px;
}

.card-body p {
  margin: 0 0 15px 0;
  font-size: 0.9rem;
}

.fallback-content {
  font-style: italic;
  opacity: 0.7;
}

/* 具名插槽演示 */
.article-layout {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

.article-header {
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.article-header h3 {
  margin: 0 0 5px 0;
  font-size: 1.3rem;
}

.author-info {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.8;
}

.article-main {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  padding: 20px;
}

.article-sidebar {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 15px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.article-content {
  font-size: 0.9rem;
  line-height: 1.6;
}

.article-footer {
  background: rgba(255, 255, 255, 0.05);
  padding: 15px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.85rem;
  opacity: 0.8;
}

/* 作用域插槽演示 */
.scoped-demo h4 {
  margin: 0 0 15px 0;
  font-size: 1.1rem;
  color: #4facfe;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}

.user-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 15px;
  text-align: center;
  transition: all 0.3s ease;
}

.user-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.user-avatar {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.user-info h5 {
  margin: 0 0 5px 0;
  font-size: 1rem;
}

.user-role {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
  opacity: 0.8;
}

.user-status {
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  color: white;
  font-weight: bold;
}

.user-simple-list {
  display: grid;
  gap: 8px;
}

.user-simple-item {
  background: rgba(255, 255, 255, 0.1);
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 0.9rem;
}

/* 高级用法演示 */
.advanced-demo {
  margin-bottom: 30px;
}

.advanced-demo h3 {
  margin: 0 0 15px 0;
  font-size: 1.2rem;
  color: #a8e6cf;
}

/* 动态插槽 */
.view-switcher {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  justify-content: center;
}

.dynamic-content {
  min-height: 200px;
}

.view-card, .view-list, .view-table {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 15px;
}

.view-card h5, .view-list h5, .view-table h5 {
  margin: 0 0 15px 0;
  font-size: 1rem;
}

.product-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}

.product-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
}

.product-card h6 {
  margin: 0 0 8px 0;
  font-size: 0.9rem;
}

.product-card p {
  margin: 0 0 5px 0;
  font-size: 0.8rem;
}

.product-list {
  display: grid;
  gap: 8px;
}

.product-list-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 15px;
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.product-table th,
.product-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.product-table th {
  background: rgba(255, 255, 255, 0.1);
  font-weight: bold;
}

/* 条件插槽 */
.toggle-controls {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  justify-content: center;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.toggle-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.layout-preview {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 15px;
}

.layout-container {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
  min-height: 200px;
}

.layout-header {
  background: rgba(79, 172, 254, 0.3);
  padding: 15px;
  text-align: center;
}

.layout-header h5 {
  margin: 0;
  font-size: 0.9rem;
}

.layout-main {
  display: flex;
  min-height: 120px;
}

.layout-sidebar {
  background: rgba(168, 230, 207, 0.3);
  width: 150px;
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-content {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-footer {
  background: rgba(245, 87, 108, 0.3);
  padding: 15px;
  text-align: center;
}

.layout-sidebar p,
.layout-content p,
.layout-footer p {
  margin: 0;
  font-size: 0.85rem;
}

/* 信息框 */
.info-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 20px;
  border-left: 4px solid #4facfe;
}

.info-box h4 {
  margin: 0 0 10px 0;
  color: #4facfe;
}

.info-box ul {
  margin: 0;
  padding-left: 20px;
}

.info-box li {
  margin-bottom: 5px;
  font-size: 0.9rem;
}

/* 最佳实践 */
.best-practices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.practice-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
}

.practice-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.practice-icon {
  font-size: 2rem;
  margin-bottom: 10px;
  text-align: center;
}

.practice-card h4 {
  margin: 0 0 10px 0;
  font-size: 1.1rem;
  text-align: center;
}

.practice-card ul {
  margin: 0;
  padding-left: 20px;
}

.practice-card li {
  margin-bottom: 5px;
  font-size: 0.85rem;
}

/* 练习任务 */
.exercise-list {
  display: grid;
  gap: 15px;
}

.exercise-item {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 20px;
  border-left: 4px solid #56ab2f;
}

.exercise-item h4 {
  margin: 0 0 10px 0;
  color: #a8e6cf;
}

.exercise-item p {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .component-slots {
    padding: 15px;
  }
  
  .demo-container {
    grid-template-columns: 1fr;
  }
  
  .concept-grid {
    grid-template-columns: 1fr;
  }
  
  .best-practices {
    grid-template-columns: 1fr;
  }
  
  .slot-demo {
    grid-template-columns: 1fr;
  }
  
  .article-main {
    grid-template-columns: 1fr;
  }
  
  .user-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  
  .view-switcher {
    flex-direction: column;
    align-items: center;
  }
  
  .toggle-controls {
    flex-direction: column;
    align-items: center;
  }
  
  .layout-main {
    flex-direction: column;
  }
  
  .layout-sidebar {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .title {
    font-size: 2rem;
  }
  
  .section {
    padding: 20px;
  }
  
  .product-cards {
    grid-template-columns: 1fr;
  }
  
  .product-list-item {
    grid-template-columns: 1fr;
    gap: 5px;
  }
}
</style>